package com.shoufeng.demo.service;

import com.shoufeng.demo.grpc.HealthCheckRequest;
import com.shoufeng.demo.grpc.HealthCheckResponse;
import com.shoufeng.demo.grpc.HealthCheckResponse.ServingStatus;
import com.shoufeng.demo.grpc.HealthGrpc.HealthImplBase;
import io.grpc.stub.StreamObserver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class HealthServiceImpl extends HealthImplBase {

  private static final Logger LOGGER = LoggerFactory.getLogger(HealthServiceImpl.class);

  @Override
  public void check(HealthCheckRequest request,
      StreamObserver<HealthCheckResponse> responseObserver) {
    String serviceName = request.getService();
    LOGGER.info("接收到check的服务: " + serviceName);
    responseObserver.onNext(HealthCheckResponse.newBuilder().setStatus(ServingStatus.SERVING).build());
    responseObserver.onCompleted();
    LOGGER.info("响应成功");
  }
}
